/** init domain config */
import './config'

import Vue from 'vue'
import App from './App.vue'
import Storage from 'vue-ls'
import router from './router'
import store from './store/'
import { VueAxios } from '@/utils/request'


import VueI18n from 'vue-i18n'
Vue.use(VueI18n)
import { get_langKey } from '@/common/storage.js'
/**
 * 设置默认语言
 */
function setLanguage() {
  let userLanguage = navigator.language || navigator.userLanguage; // 对于非英语环境，可能需要navigator.userLanguage兼容性处理
  if (userLanguage === 'zh' || userLanguage === 'zh-CN') {
      // 加载中文内容或设置中文界面
      console.log('设置中文');
      return 'zh_cn'
  } else if (userLanguage === 'en' || userLanguage === 'en-US') {
      // 加载英文内容或设置英文界面
      console.log('设置英文');
      return 'en_us'
  } else {
      // 默认语言处理
      console.log('使用默认语言');
      return 'zh_cn'
  }
}
let langKey = get_langKey() || setLanguage()
import en_us_Locale from '@/common/lang/en_us.js'
import zh_cn_Locale from '@/common/lang/zh_cn.js'
const i18n = new VueI18n({
  locale: langKey,
  //fallbackLocale: 'zh-CN',
  // 抑制警告
  silentFallbackWarn: true,
  messages: {
    //官网：'zh-CN': require('@/components/lang/zh-CN.js'),这里引入失败
    'en_us': {...en_us_Locale},
    'zh_cn': {...zh_cn_Locale}
  }
})



import Antd, { version } from 'ant-design-vue'
console.log('ant-design-vue version:', version)
import 'ant-design-vue/dist/antd.less' // or 'ant-design-vue/dist/antd.less'


// *导入自定义指令
import Directive from '@/common/directives/index.js';
Vue.use(Directive);


import Viser from 'viser-vue'

import '@/permission' // permission control
import '@/utils/filter' // base filter
import Print from 'vue-print-nb-jeecg'
/*import '@babel/polyfill'*/
import preview from 'vue-photo-preview'
import 'vue-photo-preview/dist/skin.css'
import SSO from '@/cas/sso.js'
import {
  ACCESS_TOKEN,
  DEFAULT_COLOR,
  DEFAULT_THEME,
  DEFAULT_LAYOUT_MODE,
  DEFAULT_COLOR_WEAK,
  SIDEBAR_TYPE,
  DEFAULT_FIXED_HEADER,
  DEFAULT_FIXED_HEADER_HIDDEN,
  DEFAULT_FIXED_SIDEMENU,
  DEFAULT_CONTENT_WIDTH_TYPE,
  DEFAULT_MULTI_PAGE
} from "@/store/mutation-types"
import config from '@/defaultSettings'

import JDictSelectTag from './components/dict/index.js'
import hasPermission from '@/utils/hasPermission'
import vueBus from '@/utils/vueBus';
import JeecgComponents from '@/components/jeecg/index'
import '@/assets/less/JAreaLinkage.less'
import VueAreaLinkage from 'vue-area-linkage'
//表单验证
import { rules } from '@/utils/rules'

// 引入字体配置文件
import '@/common/font/font.css'
import ElementUI from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'
Vue.use(ElementUI)
Vue.prototype.rules = rules
Vue.config.productionTip = false
Vue.use(Storage, config.storageOptions)
Vue.use(Antd)
Vue.use(VueAxios, router)
Vue.use(Viser)
Vue.use(hasPermission)
Vue.use(JDictSelectTag)
Vue.use(Print)
Vue.use(preview)
Vue.use(vueBus)
Vue.use(JeecgComponents)
Vue.use(VueAreaLinkage)

SSO.init(() => {
  main()
})
function main() {
  new Vue({
    router,
    i18n,
    store,
    mounted () {
      store.commit('SET_SIDEBAR_TYPE', Vue.ls.get(SIDEBAR_TYPE, true))
      store.commit('TOGGLE_THEME', Vue.ls.get(DEFAULT_THEME, config.navTheme))
      store.commit('TOGGLE_LAYOUT_MODE', Vue.ls.get(DEFAULT_LAYOUT_MODE, config.layout))
      store.commit('TOGGLE_FIXED_HEADER', Vue.ls.get(DEFAULT_FIXED_HEADER, config.fixedHeader))
      store.commit('TOGGLE_FIXED_SIDERBAR', Vue.ls.get(DEFAULT_FIXED_SIDEMENU, config.fixSiderbar))
      store.commit('TOGGLE_CONTENT_WIDTH', Vue.ls.get(DEFAULT_CONTENT_WIDTH_TYPE, config.contentWidth))
      store.commit('TOGGLE_FIXED_HEADER_HIDDEN', Vue.ls.get(DEFAULT_FIXED_HEADER_HIDDEN, config.autoHideHeader))
      store.commit('TOGGLE_WEAK', Vue.ls.get(DEFAULT_COLOR_WEAK, config.colorWeak))
      store.commit('TOGGLE_COLOR', Vue.ls.get(DEFAULT_COLOR, config.primaryColor))
      store.commit('SET_TOKEN', Vue.ls.get(ACCESS_TOKEN))
      store.commit('SET_MULTI_PAGE', Vue.ls.get(DEFAULT_MULTI_PAGE, config.multipage))
    },
    render: h => h(App)
  }).$mount('#app')
}
